/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormDisciplinas.java
 *
 * Created on 21/01/2012, 18:03:20
 */
package Formularios;

import Atributos.Curso;
import Atributos.Disciplina;
import Metodos.CursoMet;
import Metodos.DisciplinaMet;
import Metodos.MinimizaTela;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author André
 */

public class FormDisciplinas extends javax.swing.JFrame {
DefaultTableModel tmDisc = new DefaultTableModel(null, new String[]{"Nome"});
    List<Disciplina> Disc;
    ListSelectionModel lsmDisc;
    DefaultTableModel tmDisc2 = new DefaultTableModel(null, new String[]{"Eixo", "Curso", "Matéria"});
   
    List<Disciplina> Disc2;
    
    ListSelectionModel lsmDisc2;
    static private int id_disciplina;
private List<Curso> listaC;
 MinimizaTela tela= new MinimizaTela();  
 Curso curso=new Curso();
 CursoMet cursomet=new CursoMet();
 Disciplina disciplina=new Disciplina();
 DisciplinaMet discmet=new DisciplinaMet();
 String escolha; 
 
    public FormDisciplinas() {
        try {
            tela.Minimiza(1);
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        BufferedImage image=null;
        File imageFile=new File(".\\src\\Imagens\\logo3.png");
        try {
            image=ImageIO.read(imageFile);
            
        } catch (IOException ex) {
        }
        this.setIconImage(image);
        
//        BufferedImage image=new BufferedImage(10,10,BufferedImage.TYPE_INT_ARGB);
//        setIconImage(image);
        DesabilitaAdicionar();
        DesabilitaDelEdt();
        DesabilitaVisualizar();
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        buttonGroup3 = new javax.swing.ButtonGroup();
        jDesktopPane1 = new javax.swing.JDesktopPane();
        jPanel1 = new javax.swing.JPanel();
        jSeparator1 = new javax.swing.JSeparator();
        jRB_edt_del = new javax.swing.JRadioButton();
        jRB_adicionar = new javax.swing.JRadioButton();
        jRB_visualizar = new javax.swing.JRadioButton();
        buton_adicionar = new javax.swing.JLabel();
        buton_editar = new javax.swing.JLabel();
        buton_deletar = new javax.swing.JLabel();
        jl_nome = new javax.swing.JLabel();
        jTF_nomedisc = new javax.swing.JTextField();
        jl_eixo = new javax.swing.JLabel();
        jRB_regular = new javax.swing.JRadioButton();
        jRB_profissional = new javax.swing.JRadioButton();
        jCB_curso = new javax.swing.JComboBox();
        jl_curso = new javax.swing.JLabel();
        jCB_curso1 = new javax.swing.JComboBox();
        jl_curso2 = new javax.swing.JLabel();
        jL_ok = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTTable_disc = new javax.swing.JTable();
        jTF_pesquisar = new javax.swing.JTextField();
        jl_pesquisar = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTTabela_Disc2 = new javax.swing.JTable();
        jCB_cursoalt = new javax.swing.JComboBox();
        jl_nomealt = new javax.swing.JLabel();
        jl_cursoalt = new javax.swing.JLabel();
        jRB_profissionalalt = new javax.swing.JRadioButton();
        jRB_regularalt = new javax.swing.JRadioButton();
        jl_eixoalt = new javax.swing.JLabel();
        jTF_nomediscalt = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Disciplina");
        setResizable(false);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosed(java.awt.event.WindowEvent evt) {
                formWindowClosed(evt);
            }
        });

        jPanel1.setBackground(new java.awt.Color(0, 0, 0));
        jPanel1.setLayout(null);

        jSeparator1.setBackground(new java.awt.Color(255, 153, 0));
        jSeparator1.setForeground(new java.awt.Color(0, 0, 0));
        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);
        jPanel1.add(jSeparator1);
        jSeparator1.setBounds(170, 20, 11, 540);

        jRB_edt_del.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_edt_del);
        jRB_edt_del.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
        jRB_edt_del.setForeground(new java.awt.Color(255, 102, 0));
        jRB_edt_del.setText("<HTML>Editar<br><br>Deletar");
        jRB_edt_del.setFocusPainted(false);
        jRB_edt_del.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRB_edt_delItemStateChanged(evt);
            }
        });
        jPanel1.add(jRB_edt_del);
        jRB_edt_del.setBounds(10, 230, 140, 90);

        jRB_adicionar.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_adicionar);
        jRB_adicionar.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
        jRB_adicionar.setForeground(new java.awt.Color(255, 102, 0));
        jRB_adicionar.setText("Adicionar");
        jRB_adicionar.setFocusPainted(false);
        jRB_adicionar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRB_adicionarItemStateChanged(evt);
            }
        });
        jPanel1.add(jRB_adicionar);
        jRB_adicionar.setBounds(10, 90, 150, 30);

        jRB_visualizar.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup1.add(jRB_visualizar);
        jRB_visualizar.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
        jRB_visualizar.setForeground(new java.awt.Color(255, 102, 0));
        jRB_visualizar.setText("Visualizar");
        jRB_visualizar.setFocusPainted(false);
        jRB_visualizar.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRB_visualizarItemStateChanged(evt);
            }
        });
        jRB_visualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRB_visualizarActionPerformed(evt);
            }
        });
        jPanel1.add(jRB_visualizar);
        jRB_visualizar.setBounds(10, 450, 150, 30);

        buton_adicionar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/butonadicionar.jpg"))); // NOI18N
        buton_adicionar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        buton_adicionar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buton_adicionarMouseClicked(evt);
            }
        });
        jPanel1.add(buton_adicionar);
        buton_adicionar.setBounds(500, 520, 190, 40);

        buton_editar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/butoneditar.jpg"))); // NOI18N
        buton_editar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        buton_editar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buton_editarMouseClicked(evt);
            }
        });
        jPanel1.add(buton_editar);
        buton_editar.setBounds(340, 520, 190, 40);

        buton_deletar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/butondeletar.jpg"))); // NOI18N
        buton_deletar.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        buton_deletar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buton_deletarMouseClicked(evt);
            }
        });
        jPanel1.add(buton_deletar);
        buton_deletar.setBounds(670, 520, 190, 40);

        jl_nome.setBackground(new java.awt.Color(0, 0, 0));
        jl_nome.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
        jl_nome.setForeground(new java.awt.Color(255, 255, 255));
        jl_nome.setText("Nome:");
        jPanel1.add(jl_nome);
        jl_nome.setBounds(230, 90, 79, 30);

        jTF_nomedisc.setBackground(new java.awt.Color(0, 0, 0));
        jTF_nomedisc.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jTF_nomedisc.setForeground(new java.awt.Color(255, 255, 255));
        jTF_nomedisc.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTF_nomedisc.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(255, 255, 255)));
        jTF_nomedisc.setCaretColor(new java.awt.Color(255, 255, 255));
        jPanel1.add(jTF_nomedisc);
        jTF_nomedisc.setBounds(330, 90, 590, 25);

        jl_eixo.setBackground(new java.awt.Color(0, 0, 0));
        jl_eixo.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
        jl_eixo.setForeground(new java.awt.Color(255, 255, 255));
        jl_eixo.setText("Eixo:");
        jPanel1.add(jl_eixo);
        jl_eixo.setBounds(230, 220, 79, 17);

        jRB_regular.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup2.add(jRB_regular);
        jRB_regular.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
        jRB_regular.setForeground(new java.awt.Color(255, 102, 0));
        jRB_regular.setText("Regular");
        jRB_regular.setFocusPainted(false);
        jRB_regular.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRB_regularItemStateChanged(evt);
            }
        });
        jPanel1.add(jRB_regular);
        jRB_regular.setBounds(410, 220, 150, 30);

        jRB_profissional.setBackground(new java.awt.Color(0, 0, 0));
        buttonGroup2.add(jRB_profissional);
        jRB_profissional.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
        jRB_profissional.setForeground(new java.awt.Color(255, 102, 0));
        jRB_profissional.setText("Profissional");
        jRB_profissional.setFocusPainted(false);
        jRB_profissional.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jRB_profissionalItemStateChanged(evt);
            }
        });
        jPanel1.add(jRB_profissional);
        jRB_profissional.setBounds(680, 220, 190, 30);

        jCB_curso.setBackground(new java.awt.Color(0, 0, 0));
        jCB_curso.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jPanel1.add(jCB_curso);
        jCB_curso.setBounds(520, 370, 200, 27);

        jl_curso.setBackground(new java.awt.Color(0, 0, 0));
        jl_curso.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
        jl_curso.setForeground(new java.awt.Color(255, 255, 255));
        jl_curso.setText("Curso:");
        jPanel1.add(jl_curso);
        jl_curso.setBounds(580, 330, 79, 17);

        jCB_curso1.setBackground(new java.awt.Color(0, 0, 0));
        jCB_curso1.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
        jCB_curso1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(jCB_curso1);
        jCB_curso1.setBounds(480, 90, 170, 27);

        jl_curso2.setBackground(new java.awt.Color(0, 0, 0));
        jl_curso2.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
        jl_curso2.setForeground(new java.awt.Color(255, 255, 255));
        jl_curso2.setText("Curso:");
        jPanel1.add(jl_curso2);
        jl_curso2.setBounds(380, 100, 79, 17);

        jL_ok.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Imagens/OKlay1.jpg"))); // NOI18N
        jL_ok.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jL_ok.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jL_okMouseClicked(evt);
            }
        });
        jPanel1.add(jL_ok);
        jL_ok.setBounds(780, 80, 71, 50);

        jScrollPane1.setBackground(new java.awt.Color(0, 0, 0));
        jScrollPane1.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
        jScrollPane1.setForeground(new java.awt.Color(255, 51, 0));
        jScrollPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N

        jTTable_disc.setBackground(new java.awt.Color(0, 0, 0));
        jTTable_disc.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jTTable_disc.setForeground(new java.awt.Color(255, 255, 255));
        jTTable_disc.setModel(tmDisc        );
        jTTable_disc.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jTTable_disc.setGridColor(new java.awt.Color(255, 255, 255));
        jTTable_disc.setInheritsPopupMenu(true);
        jTTable_disc.setSelectionBackground(new java.awt.Color(255, 255, 255));
        jTTable_disc.setSelectionForeground(new java.awt.Color(0, 0, 0));
        jTTable_disc.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        lsmDisc = jTTable_disc.getSelectionModel();
        lsmDisc.addListSelectionListener(new ListSelectionListener(){
            public void valueChanged(ListSelectionEvent e){
                if(! e.getValueIsAdjusting()){
                    JTTabelaLinhaSelecionada(jTTable_disc);
                }
            }
        }
    );
    jScrollPane1.setViewportView(jTTable_disc);

    jPanel1.add(jScrollPane1);
    jScrollPane1.setBounds(200, 180, 780, 300);

    jTF_pesquisar.setBackground(new java.awt.Color(0, 0, 0));
    jTF_pesquisar.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
    jTF_pesquisar.setForeground(new java.awt.Color(255, 255, 255));
    jTF_pesquisar.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    jTF_pesquisar.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(255, 255, 255)));
    jTF_pesquisar.setCaretColor(new java.awt.Color(255, 255, 255));
    jTF_pesquisar.addKeyListener(new java.awt.event.KeyAdapter() {
        public void keyReleased(java.awt.event.KeyEvent evt) {
            jTF_pesquisarKeyReleased(evt);
        }
    });
    jPanel1.add(jTF_pesquisar);
    jTF_pesquisar.setBounds(220, 40, 520, 25);

    jl_pesquisar.setBackground(new java.awt.Color(0, 0, 0));
    jl_pesquisar.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
    jl_pesquisar.setForeground(new java.awt.Color(255, 255, 255));
    jl_pesquisar.setText("PESQUISAR");
    jPanel1.add(jl_pesquisar);
    jl_pesquisar.setBounds(780, 40, 130, 30);

    jScrollPane2.setBackground(new java.awt.Color(0, 0, 0));
    jScrollPane2.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
    jScrollPane2.setForeground(new java.awt.Color(51, 204, 0));
    jScrollPane2.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

    jTTabela_Disc2.setBackground(new java.awt.Color(0, 0, 0));
    jTTabela_Disc2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
    jTTabela_Disc2.setForeground(new java.awt.Color(255, 255, 255));
    jTTabela_Disc2.setModel(tmDisc2);
    jTTabela_Disc2.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
    jTTabela_Disc2.setGridColor(new java.awt.Color(255, 255, 255));
    jTTabela_Disc2.setSelectionBackground(new java.awt.Color(255, 255, 255));
    jTTabela_Disc2.setSelectionForeground(new java.awt.Color(0, 0, 0));
    jTTabela_Disc2.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    lsmDisc2 = jTTabela_Disc2.getSelectionModel();
    lsmDisc2.addListSelectionListener(new ListSelectionListener(){
        public void valueChanged(ListSelectionEvent e){
            if(! e.getValueIsAdjusting()){
                JTTabelaLinhaSelecionada2(jTTabela_Disc2);
            }
        }
    }
    );
    jScrollPane2.setViewportView(jTTabela_Disc2);

    jPanel1.add(jScrollPane2);
    jScrollPane2.setBounds(190, 90, 790, 160);

    jCB_cursoalt.setBackground(new java.awt.Color(0, 0, 0));
    jCB_cursoalt.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
    jPanel1.add(jCB_cursoalt);
    jCB_cursoalt.setBounds(650, 390, 180, 27);

    jl_nomealt.setBackground(new java.awt.Color(0, 0, 0));
    jl_nomealt.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
    jl_nomealt.setForeground(new java.awt.Color(255, 255, 255));
    jl_nomealt.setText("Nome:");
    jPanel1.add(jl_nomealt);
    jl_nomealt.setBounds(210, 310, 79, 30);

    jl_cursoalt.setBackground(new java.awt.Color(0, 0, 0));
    jl_cursoalt.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
    jl_cursoalt.setForeground(new java.awt.Color(255, 255, 255));
    jl_cursoalt.setText("Curso:");
    jPanel1.add(jl_cursoalt);
    jl_cursoalt.setBounds(650, 360, 130, 17);

    jRB_profissionalalt.setBackground(new java.awt.Color(0, 0, 0));
    buttonGroup3.add(jRB_profissionalalt);
    jRB_profissionalalt.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
    jRB_profissionalalt.setForeground(new java.awt.Color(255, 102, 0));
    jRB_profissionalalt.setText("Profissional");
    jRB_profissionalalt.setFocusPainted(false);
    jRB_profissionalalt.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            jRB_profissionalaltItemStateChanged(evt);
        }
    });
    jPanel1.add(jRB_profissionalalt);
    jRB_profissionalalt.setBounds(290, 420, 190, 30);

    jRB_regularalt.setBackground(new java.awt.Color(0, 0, 0));
    buttonGroup3.add(jRB_regularalt);
    jRB_regularalt.setFont(new java.awt.Font("D3 Euronism italic", 0, 18)); // NOI18N
    jRB_regularalt.setForeground(new java.awt.Color(255, 102, 0));
    jRB_regularalt.setText("Regular");
    jRB_regularalt.setFocusPainted(false);
    jRB_regularalt.addItemListener(new java.awt.event.ItemListener() {
        public void itemStateChanged(java.awt.event.ItemEvent evt) {
            jRB_regularaltItemStateChanged(evt);
        }
    });
    jPanel1.add(jRB_regularalt);
    jRB_regularalt.setBounds(290, 370, 150, 30);

    jl_eixoalt.setBackground(new java.awt.Color(0, 0, 0));
    jl_eixoalt.setFont(new java.awt.Font("D3 Euronism italic", 1, 14)); // NOI18N
    jl_eixoalt.setForeground(new java.awt.Color(255, 255, 255));
    jl_eixoalt.setText("Eixo:");
    jPanel1.add(jl_eixoalt);
    jl_eixoalt.setBounds(210, 400, 79, 17);

    jTF_nomediscalt.setBackground(new java.awt.Color(0, 0, 0));
    jTF_nomediscalt.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
    jTF_nomediscalt.setForeground(new java.awt.Color(255, 255, 255));
    jTF_nomediscalt.setHorizontalAlignment(javax.swing.JTextField.CENTER);
    jTF_nomediscalt.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(255, 255, 255)));
    jTF_nomediscalt.setCaretColor(new java.awt.Color(255, 255, 255));
    jPanel1.add(jTF_nomediscalt);
    jTF_nomediscalt.setBounds(290, 310, 660, 25);

    jLabel1.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(255, 255, 255)), "Novo", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("D3 Euronism italic", 1, 14), new java.awt.Color(255, 102, 0))); // NOI18N
    jPanel1.add(jLabel1);
    jLabel1.setBounds(190, 270, 790, 220);

    jPanel1.setBounds(0, 0, 1010, 900);
    jDesktopPane1.add(jPanel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 997, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addComponent(jDesktopPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE)
    );

    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width-1013)/2, (screenSize.height-622)/2, 1013, 622);
    }// </editor-fold>//GEN-END:initComponents

private void formWindowClosed(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosed
try {
            tela.Minimiza(0);
        } catch (SQLException ex) {
            Logger.getLogger(FormCursos.class.getName()).log(Level.SEVERE, null, ex);
        }
       java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new ChamaLayout().setVisible(true);
            }
        }); 
}//GEN-LAST:event_formWindowClosed

private void jRB_adicionarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_adicionarItemStateChanged
DesabilitaDelEdt();
DesabilitaVisualizar();
escolha=jRB_adicionar.getText();
ChamaEscolha(escolha);
}//GEN-LAST:event_jRB_adicionarItemStateChanged

private void jRB_edt_delItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_edt_delItemStateChanged
 if(jRB_edt_del.isSelected()){
        if(VerificaBD()){
DesabilitaAdicionar();
DesabilitaVisualizar();
escolha=jRB_edt_del.getText();
ChamaEscolha(escolha);  
InicializaDadosEdlDel();

}else{
DesabilitaAdicionar();
DesabilitaDelEdt();
    JOptionPane.showMessageDialog(null, "Não ha disciplinas a serem editadas nem deletadas!");
     buttonGroup1.clearSelection();

}
}
}//GEN-LAST:event_jRB_edt_delItemStateChanged

private void jRB_visualizarItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_visualizarItemStateChanged
    if(jRB_visualizar.isSelected()){
        if(VerificaBD() && VerificaBD2()){
DesabilitaAdicionar();  
DesabilitaDelEdt();
escolha=jRB_visualizar.getText();
ChamaEscolha(escolha); 
InicializaDadosProfissionais2();
        }else{
            JOptionPane.showMessageDialog(null, "Não ha disciplinas profissionais a serem visualizadas!");
            buttonGroup1.clearSelection();
            DesabilitaAdicionar();
            DesabilitaDelEdt();
        }
    }
}//GEN-LAST:event_jRB_visualizarItemStateChanged

    private void jRB_profissionalItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_profissionalItemStateChanged
if(jRB_profissional.isSelected()){
    if(VerificaBD2()){
    jl_curso.setVisible(true);
        
        jCB_curso.setVisible(true);
        
        InicializaDadosProfissionais();
        
    }else{ 
    JOptionPane.showMessageDialog(null, "Não ha cursos a serem selecionados!");
     buttonGroup2.clearSelection();
}
}else{
   
    jl_curso.setVisible(false);
        
        jCB_curso.setVisible(false);
        
}
    }//GEN-LAST:event_jRB_profissionalItemStateChanged

    private void jRB_regularItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_regularItemStateChanged
       
    }//GEN-LAST:event_jRB_regularItemStateChanged

    private void buton_adicionarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buton_adicionarMouseClicked
       if(VerificaDadosCorretosADD()){
           if(jRB_regular.isSelected()){
               disciplina.setNome(jTF_nomedisc.getText());
               disciplina.setEixo(jRB_regular.getText());
               if(discmet.BuscaDisciplinaRegseiguais(disciplina)){
                    try {
                        discmet.AdicionaDisciplina(disciplina,curso);
                    } catch (SQLException ex) {
                        Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
                    }
                   JOptionPane.showMessageDialog(null, "Adicionado com sucesso!");
            limpaDadosAdicionar();
               }else{
                   JOptionPane.showMessageDialog(null, "Esta disciplina já existe!");
               }
           }else{
               disciplina.setNome(jTF_nomedisc.getText());
               disciplina.setEixo(jRB_profissional.getText());
               curso.setId_curso(cursomet.Buscar_ID_Curso(jCB_curso.getSelectedItem().toString())); 
               
               System.out.println("id_curso: "+curso.getId_curso()+" id_descricao: "+curso.getId_descricao());
               if(discmet.BuscaDisciplinaProfseiguais(disciplina,curso)){
                    try {
                        discmet.AdicionaDisciplina(disciplina,curso);
                    } catch (SQLException ex) {
                        Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
                    }
                    JOptionPane.showMessageDialog(null, "Adicionado com sucesso!");
            limpaDadosAdicionar();
               }else{
                   JOptionPane.showMessageDialog(null, "Esta disciplina já existe!");
               }
              
           }
       }else{
           JOptionPane.showMessageDialog(null, "Dados Incorretos");
       }
    }//GEN-LAST:event_buton_adicionarMouseClicked

    private void jL_okMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jL_okMouseClicked
if(VerificaDiscipinaBD(jCB_curso1.getSelectedItem().toString())){       
    try {
        
            Disc=discmet.BuscarDisciplinaCurso(jCB_curso1.getSelectedItem().toString());
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
mostraPesquisa(Disc);
}else{
    while (tmDisc.getRowCount() > 0) {
            tmDisc.removeRow(0);
        }
    JOptionPane.showMessageDialog(null, "Não há disciplinas neste curso!");
}
    }//GEN-LAST:event_jL_okMouseClicked

    private void jTF_pesquisarKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTF_pesquisarKeyReleased
       InicializaDadosEdlDel();
    }//GEN-LAST:event_jTF_pesquisarKeyReleased

    private void jRB_profissionalaltItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_profissionalaltItemStateChanged
       if(jRB_profissionalalt.isSelected()){
           if(Verificasehacursos()){
         jCB_cursoalt.setVisible(true); 
         
         jl_cursoalt.setVisible(true);
         
          
        String[] cursos = cursomet.Buscar_Nome_Cursos();
        jCB_cursoalt.setModel(new javax.swing.DefaultComboBoxModel(cursos));
        
//        listaC=cursomet.BuscarTodasDescriçoes();
//        descrição = new String[listaC.size()];
//        for(int i = 0;listaC.size()>i;i++){
//        curso = listaC.get(i);
//        descrição[i] = curso.getDescrição(); 
//        }
//        jCB_descricaoalt.setModel(new javax.swing.DefaultComboBoxModel(descrição));
        
           }else{
               JOptionPane.showMessageDialog(null, "Não ha cursos adicionados!");
           }
       }
    }//GEN-LAST:event_jRB_profissionalaltItemStateChanged

    private void jRB_regularaltItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jRB_regularaltItemStateChanged
jCB_cursoalt.setVisible(false); 
         
         jl_cursoalt.setVisible(false);
             
    }//GEN-LAST:event_jRB_regularaltItemStateChanged

    private void buton_editarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buton_editarMouseClicked
       if(VerificaDadosCorretosALTDEL()){
           String a;
           
           disciplina.setNome(jTF_nomediscalt.getText());
           disciplina.setId_disc(id_disciplina);
           if(jRB_profissionalalt.isSelected()){
            a=jRB_profissionalalt.getText();  
            
           disciplina.setId_curso(cursomet.Buscar_ID_Curso(jCB_cursoalt.getSelectedItem().toString()));
           
       }else{
           a=jRB_regularalt.getText();
       }
           disciplina.setEixo(a);
           try {
                discmet.AlteraDisciplina(disciplina);
            } catch (SQLException ex) {
                Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(null, "Alterado com sucesso");
            limpaDadosALTDEL();
       }else{
           JOptionPane.showMessageDialog(null, "Dados Incorretos");
       }
    }//GEN-LAST:event_buton_editarMouseClicked

    private void buton_deletarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buton_deletarMouseClicked
if(jTTabela_Disc2.getSelectedRow()!=-1){ 
        int resp = JOptionPane.showConfirmDialog(this, "Deseja realmente excluir esta disciplina?",
                "Confirmação", JOptionPane.YES_NO_OPTION);

        if (resp == JOptionPane.YES_NO_OPTION) {
            try {
                discmet.ExcluiDisciplina(Disc2.get(jTTabela_Disc2.getSelectedRow()));
            } catch (SQLException ex) {
                Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
            }
            
            JOptionPane.showMessageDialog(null, "Excluido com sucesso");
            limpaDadosALTDEL();
            try {
            Disc2 = discmet.BuscarDisciplinas(jTF_pesquisar.getText() + "%");
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        mostraPesquisa2(Disc2);
        }
        }else{
    JOptionPane.showMessageDialog(null, "Nada selecionado");
}
    }//GEN-LAST:event_buton_deletarMouseClicked

    private void jRB_visualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRB_visualizarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRB_visualizarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FormDisciplinas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FormDisciplinas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FormDisciplinas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FormDisciplinas.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new FormDisciplinas().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel buton_adicionar;
    private javax.swing.JLabel buton_deletar;
    private javax.swing.JLabel buton_editar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.ButtonGroup buttonGroup3;
    private javax.swing.JComboBox jCB_curso;
    private javax.swing.JComboBox jCB_curso1;
    private javax.swing.JComboBox jCB_cursoalt;
    private javax.swing.JDesktopPane jDesktopPane1;
    private javax.swing.JLabel jL_ok;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JRadioButton jRB_adicionar;
    private javax.swing.JRadioButton jRB_edt_del;
    private javax.swing.JRadioButton jRB_profissional;
    private javax.swing.JRadioButton jRB_profissionalalt;
    private javax.swing.JRadioButton jRB_regular;
    private javax.swing.JRadioButton jRB_regularalt;
    private javax.swing.JRadioButton jRB_visualizar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTextField jTF_nomedisc;
    private javax.swing.JTextField jTF_nomediscalt;
    private javax.swing.JTextField jTF_pesquisar;
    private javax.swing.JTable jTTabela_Disc2;
    private javax.swing.JTable jTTable_disc;
    private javax.swing.JLabel jl_curso;
    private javax.swing.JLabel jl_curso2;
    private javax.swing.JLabel jl_cursoalt;
    private javax.swing.JLabel jl_eixo;
    private javax.swing.JLabel jl_eixoalt;
    private javax.swing.JLabel jl_nome;
    private javax.swing.JLabel jl_nomealt;
    private javax.swing.JLabel jl_pesquisar;
    // End of variables declaration//GEN-END:variables

    private void DesabilitaDelEdt() {
        jTTabela_Disc2.clearSelection();
        jTF_pesquisar.setText("");
       while (tmDisc2.getRowCount() > 0) {
            tmDisc2.removeRow(0);
        }
       
  buton_deletar.setVisible(false);  
  buton_editar.setVisible(false);
  jl_pesquisar.setVisible(false);
        jTF_pesquisar.setVisible(false);
        jScrollPane2.setVisible(false);
        jTTabela_Disc2.setVisible(false);
        jl_nomealt.setVisible(false);
        jLabel1.setVisible(false);
        jl_eixoalt.setVisible(false);
        jRB_profissionalalt.setVisible(false);
        jRB_regularalt.setVisible(false);
        jTF_nomediscalt.setVisible(false);
    }
    private void DesabilitaAdicionar() {
        buttonGroup2.clearSelection();
        buton_adicionar.setVisible(false);
        jl_nome.setVisible(false);
        jTF_nomedisc.setVisible(false);
        jl_eixo.setVisible(false);
        jRB_regular.setVisible(false);
        jRB_profissional.setVisible(false);
        jl_curso.setVisible(false);
        
        jCB_curso.setVisible(false);
        
       
    }

    private void DesabilitaVisualizar() {
        jTTable_disc.clearSelection();
         while (tmDisc.getRowCount() > 0) {
            tmDisc.removeRow(0);
        }
        jL_ok.setVisible(false);
        jCB_curso1.setVisible(false);
        
        jl_curso2.setVisible(false);
        
        jScrollPane1.setVisible(false);
        jTTable_disc.setVisible(false);
        jCB_cursoalt.setVisible(false); 
         
         jl_cursoalt.setVisible(false);
         
    }
    private void ChamaEscolha(String escolha) {
        if("Adicionar".equals(escolha)){
        buton_adicionar.setVisible(true);
        jl_nome.setVisible(true);
        jTF_nomedisc.setVisible(true);
        jl_eixo.setVisible(true);
        jRB_regular.setVisible(true);
        jRB_profissional.setVisible(true);
        
        
        }else if("<HTML>Editar<br><br>Deletar".equals(escolha)){
        buton_editar.setVisible(true);
        buton_deletar.setVisible(true);
        jl_pesquisar.setVisible(true);
        jTF_pesquisar.setVisible(true);
        jScrollPane2.setVisible(true);
        jTTabela_Disc2.setVisible(true);
        jl_nomealt.setVisible(true);
        jLabel1.setVisible(true);
        jl_eixoalt.setVisible(true);
        jRB_profissionalalt.setVisible(true);
        jRB_regularalt.setVisible(true);
         jTF_nomediscalt.setVisible(true);

        }else if("Visualizar".equals(escolha)){
         jL_ok.setVisible(true);
        jCB_curso1.setVisible(true);
        
        jl_curso2.setVisible(true);
        
        jScrollPane1.setVisible(true);
        jTTable_disc.setVisible(true);
        
         
        }
    }

    private void InicializaDadosProfissionais() {
        String[] cursos = cursomet.Buscar_Nome_Cursos();
        jCB_curso.setModel(new javax.swing.DefaultComboBoxModel(cursos));
        
    }

   

    private boolean VerificaBD() {
        List<Disciplina> disci = null;
        try {
            disci = discmet.BuscarDisciplinas("%");
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(disci.isEmpty()){
            return false;
        }else{
            return true;
        }
    }

    private void DesabilitaProfissional() {
        jl_curso.setVisible(false);
        
        jCB_curso.setVisible(false);
        
    }

    private boolean VerificaDadosCorretosADD() {
        if("".equals(jTF_nomedisc.getText()) || buttonGroup2.getSelection()==null) {
            return false;
        }else {
            return true;
        }
    }

    private void limpaDadosAdicionar() {
        jTF_nomedisc.setText("");
        buttonGroup2.clearSelection();
    }
    
    private void JTTabelaLinhaSelecionada(JTable tabela) {
        
    }

    private void InicializaDadosProfissionais2() {
       String[] cursos = cursomet.Buscar_Nome_Cursos();
        jCB_curso1.setModel(new javax.swing.DefaultComboBoxModel(cursos));
        
    }

    

    private void mostraPesquisa2(List<Disciplina> Disc2) {
        while (tmDisc2.getRowCount() > 0) {
            tmDisc2.removeRow(0);
        }
        if (Disc2.isEmpty()) {
          
        } else {
            String[] linha = new String[]{null, null, null};
            for (int i = 0; i < Disc2.size(); i++) {
                if(Disc2.get(i).getEixo().equals("Regular")){
                tmDisc2.addRow(linha);
                tmDisc2.setValueAt(Disc2.get(i).getEixo(), i, 0);
                tmDisc2.setValueAt(Disc2.get(i).getNome(), i, 2);
                }
                else if(Disc2.get(i).getEixo().equals("Profissional")){
                tmDisc2.addRow(linha);
                tmDisc2.setValueAt(Disc2.get(i).getEixo(), i, 0);
                tmDisc2.setValueAt(Disc2.get(i).getNomecurso(), i, 1);
                tmDisc2.setValueAt(Disc2.get(i).getNome(), i, 2);
                }
                
                
            }
            
            }
    }

    private boolean VerificaDiscipinaBD(String curso) {
        try {
            Disc =  discmet.BuscarDisciplinaCurso(curso);
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
        if(Disc.isEmpty()){
            return false;
        }else{
            return true;
        }
    }
    
    private void JTTabelaLinhaSelecionada2(JTable tabela) {
        if (jTTabela_Disc2.getSelectedRow() > -1) {
            id_disciplina=Disc2.get(tabela.getSelectedRow()).getId_disc();
            jTF_nomediscalt.setText(String.valueOf(Disc2.get(tabela.getSelectedRow()).getNome()));
            if(Disc2.get(tabela.getSelectedRow()).getEixo().equals("Regular")){
                jRB_regularalt.setSelected(true);
               jCB_cursoalt.setVisible(false); 
         
         jl_cursoalt.setVisible(false);
         
            }else{
                jRB_profissionalalt.setSelected(true);
                jCB_cursoalt.setVisible(true); 
         
         jl_cursoalt.setVisible(true);
         
            jCB_cursoalt.setSelectedItem((Disc2.get(tabela.getSelectedRow()).getNomecurso()));
            
            }
            

  }else {
            id_disciplina=0;
            jTF_nomediscalt.setText("");
            buttonGroup3.clearSelection();
               jCB_cursoalt.setVisible(false); 
         
         jl_cursoalt.setVisible(false);
         
        }
 
    }

    private void InicializaDadosEdlDel() {
        try {
            Disc2 = discmet.BuscarDisciplinas(jTF_pesquisar.getText() + "%");
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        mostraPesquisa2(Disc2);
        
        String[] cursos = cursomet.Buscar_Nome_Cursos();
        jCB_cursoalt.setModel(new javax.swing.DefaultComboBoxModel(cursos));
        
        
    }

    private void mostraPesquisa(List<Disciplina> Disc) {
        while (tmDisc.getRowCount() > 0) {
            tmDisc.removeRow(0);
        }
        if (Disc.isEmpty()) {
        } else {
            String[] linha = new String[]{null};
            for (int i = 0; i < Disc.size(); i++) {
                tmDisc.addRow(linha);
                tmDisc.setValueAt(Disc.get(i).getNome(), i, 0);
                
                
            }
        }
    }

    

    private boolean VerificaDadosCorretosALTDEL() {
        if("".equals(jTF_nomediscalt.getText()) ){
            return false;
        }else {
            return true;
        }
    }

    private void limpaDadosALTDEL() {
        jTTabela_Disc2.clearSelection();
        jTF_pesquisar.setText("");
        jTF_nomediscalt.setText("");
        buttonGroup3.clearSelection();
        try {
            Disc2 = discmet.BuscarDisciplinas(jTF_pesquisar.getText() + "%");
        } catch (SQLException ex) {
            Logger.getLogger(FormDisciplinas.class.getName()).log(Level.SEVERE, null, ex);
        }
       
        mostraPesquisa2(Disc2);
    }

    private boolean Verificasehacursos() {
         String[] cursos = cursomet.Buscar_Nome_Cursos();
        if(cursos.length==0){
            return false;
        }else{
            return true;
        }
    }

    private boolean VerificaBD2() {
        String[] disci = null;
      
            disci = cursomet.Buscar_Nome_Cursos();
       
        if(disci.length==0){
            return false;
        }else{
            return true;
        }
    }
}
